package com.xy.order.controller;
import com.ruoyi.common.core.domain.home.Orders;
import com.ruoyi.common.core.domain.order.dto.OrderDetailDTO;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.xy.order.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;

import java.util.List;

/**
 * 订单Controller
 *
 * @author ruoyi
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/order1")
public class OrdersController extends BaseController
{
    @Autowired
    private IOrdersService ordersService;

    /**
     * 查询订单详情
     */
    @RequiresPermissions("order:order1:list")
    @GetMapping(value = "/list")
    public TableDataInfo getInfo()
    {
        startPage();
        List<OrderDetailDTO> list = ordersService.findAllOrderDetails();
        return getDataTable(list);
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("order:order1:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ordersService.selectOrdersById(id));
    }

    
    /**
     * 新增订单
     */
    @RequiresPermissions("order:order1:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Orders orders)
    {
        return toAjax(ordersService.insertOrders(orders));
    }

    /**
     * 修改订单
     */
    @RequiresPermissions("order:order1:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Orders orders)
    {
        return toAjax(ordersService.updateOrders(orders));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("order:order1:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ordersService.deleteOrdersByIds(ids));
    }
}

